<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        window.addEventListener('popstate', event => {
          console.log(
            `location: ${document.location}, state: ${JSON.stringify(event.state)}`,
          );
        });

        // history.pushState({ page: 1 }, 'title 1', '?page=1');
        // history.pushState({ page: 2 }, 'title 2', '?page=2');
        // history.replaceState({ page: 3 }, 'title 3', '?page=3');
        // history.back();
        // 弹出 "location: http://example.com/example.html?page=1, state: {"page":1}"
        // history.back(); // 弹出 "location: http://example.com/example.html, state: null
        // history.go(2); // 弹出 "location: http://example.com/example.html?page=3, state: {"page":3}
    </script>
</body>

</html>